/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.order.model;

import cn.ekuma.epos.businesslogic.OrderUtil;
import com.openbravo.format.Formats;
import com.openbravo.pos.base.AppLocal;
import com.openbravo.bean.erp.viewbean.FindOrdersInfo;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Administrator
 */
public class OrderInfoTableModel extends AbstractTableModel {
       public static String[] TABLECOLUMNS_OrderInfo=new String[]{
                                  AppLocal.getIntString("label.orderid"),
                                  AppLocal.getIntString("label.ordertype"),
                                  AppLocal.getIntString("label.ordertypedialog.bearing"),
                                  AppLocal.getIntString("label.date"),
                                  AppLocal.getIntString("label.customer"),
                                  AppLocal.getIntString("label.location"),
                                  AppLocal.getIntString("Menu.Users"),
                                  AppLocal.getIntString("label.totalcash"),
                                  AppLocal.getIntString("label.notes"),
                                  AppLocal.getIntString("label.orderStates"),
                                  AppLocal.getIntString("label.referncePerson"),
                                  AppLocal.getIntString("label.address2"),
                                  AppLocal.getIntString("label.priceRate"),
                                  AppLocal.getIntString("label.curdebt")
   };

        private java.util.List m_data;

        public OrderInfoTableModel(java.util.List data) {
            m_data = data;
            if(m_data==null)
                m_data = new ArrayList();
        }

        public int getRowCount() {
            return m_data.size();
        }

        public Object getRow(int rowIndex){
            return m_data.get(rowIndex);
        }

        public int getColumnCount() {
          return   TABLECOLUMNS_OrderInfo.length;
        }

        @Override
        public String getColumnName(int column) {
            return TABLECOLUMNS_OrderInfo[column];
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
            FindOrdersInfo orderInfo=(FindOrdersInfo) m_data.get(rowIndex);
            switch(columnIndex){
                case 0:
                    return orderInfo.getOrderId();
                case 1:
                    return orderInfo.getDefineType();
                case 2:
                    return orderInfo.getOrderType()==0?OrderUtil.ORDERTYPE_Normal:OrderUtil.ORDERTYPE_Revoerse;
                case 3:
                    return Formats.TIMESTAMP.formatValue(orderInfo.getDate());
                case 4:
                    return orderInfo.getCustomer()==null?"":orderInfo.getCustomer();
                case 5:
                     return orderInfo.getLocation();
                case 6:
                     return orderInfo.getName();
                case 7:
                      return Formats.CURRENCY.formatValue(orderInfo.getTotalPrice());
                case 8:
                      return orderInfo.getMemo();
                case 9:
                      return orderInfo.getCurrentState();
                case 10:
                      return orderInfo.getM_sResponse();
                case 11:
                      return orderInfo.getLocationRef1();
                case 12:
                      return Formats.PERCENT.formatValue(orderInfo.getM_dPriceRate());
                case 13:
                	  return Formats.CURRENCY.formatValue(orderInfo.getDebt());
            }
            return null;
        }

        public void setData(List data){
            m_data=data;
            this.fireTableDataChanged();
        }

        public static String getOrderInfoDescription(FindOrdersInfo orderInfo){
        String orderType=orderInfo.getOrderType()==0?OrderUtil.ORDERTYPE_Normal:OrderUtil.ORDERTYPE_Revoerse;
        String buildStr=TABLECOLUMNS_OrderInfo[0]+":"+orderInfo.getOrderId()+"\n"+
                        TABLECOLUMNS_OrderInfo[1]+":"+orderInfo.getDefineType()+"\n"+
                        TABLECOLUMNS_OrderInfo[2]+":"+orderType+"\n"+
                        TABLECOLUMNS_OrderInfo[3]+":"+Formats.TIMESTAMP.formatValue(orderInfo.getDate())+"\n"+
                        TABLECOLUMNS_OrderInfo[4]+":"+(orderInfo.getCustomer()==null?"":orderInfo.getCustomer())+"\n"+
                        TABLECOLUMNS_OrderInfo[5]+":"+orderInfo.getLocation()+"\n"+
                        TABLECOLUMNS_OrderInfo[6]+":"+orderInfo.getName()+"\n"+
                        TABLECOLUMNS_OrderInfo[7]+":"+Formats.CURRENCY.formatValue(orderInfo.getTotalPrice())+"\n"+
                        TABLECOLUMNS_OrderInfo[8]+":"+(orderInfo.getMemo()==null?"":orderInfo.getMemo())+"\n"+
                        TABLECOLUMNS_OrderInfo[9]+":"+orderInfo.getCurrentState()+"\n"+
                        TABLECOLUMNS_OrderInfo[10]+":"+(orderInfo.getM_sResponse()==null?"":orderInfo.getM_sResponse())+"\n"+
                        TABLECOLUMNS_OrderInfo[11]+":"+(orderInfo.getLocationRef1()==null?"":orderInfo.getLocationRef1())+"\n"+
                        TABLECOLUMNS_OrderInfo[12]+":"+Formats.PERCENT.formatValue(orderInfo.getM_dPriceRate())+"\n"+
                        TABLECOLUMNS_OrderInfo[13]+":"+Formats.CURRENCY.formatValue(orderInfo.getDebt())+"\n";
        return buildStr;
    }
}

